package org.dant.ant.extension.net.repository;

import java.util.*;
import org.dant.ant.extension.utils.StringUtils;

public class ProcessItem {

  protected String processID;   // real process id get from os
  
  protected Process process;
  
  protected long startTime;
  protected long timeOut;
  protected String status;

  protected ProcessGroup group;

  public void setStatus(String status) {
    this.status = status;
  }

  public String getStatus() {
    return this.status;
  }

  public long runningTime() {
    return System.currentTimeMillis() - startTime;
  }

  public void destroy() {
    if (process != null)
      process.destroy();
  }

  public void add(Process process) {
    this.process = process;
  }

  public Process getProcess() {
    return process;
  }
  
  public void setProcessID(String processid) {
    this.processID = processid;
  }

  public String getProcessID() {
    return this.processID;
  }

  public void setStartTime(long startTime) {
    this.startTime = startTime;
  }

  public long getStartTime() {
    return this.startTime;
  }

  public void setTimeOut(long timeOut) {
    this.timeOut = timeOut;
  }

  public long getTimeOut() {
    return this.timeOut;
  }

  public void setOwningGroup(ProcessGroup group) {
    this.group = group;
  }

  public ProcessGroup getOwningGroup() {
    return this.group;
  }

  public String export() {
    StringBuffer sb = new StringBuffer();
    sb.append(StringUtils.formatln("***** Process Item *****", 6));
    sb.append(StringUtils.format("Process ID: ", 8));
    sb.append(StringUtils.formatln(processID+""));
    sb.append(StringUtils.format("Start time: ", 8));
    sb.append(StringUtils.formatln(new Date(startTime).toString()));
    sb.append(StringUtils.format("Timeout: ", 8));
    sb.append(StringUtils.formatln(timeOut+""));
    sb.append(StringUtils.format("Status: ", 8));
    sb.append(StringUtils.formatln(status));

    return sb.toString();
  }
}
